package com.gykfbxxh.imovie.listener;

import com.android.volley.Response;
import com.android.volley.VolleyError;

/**
 * 自定义的网络请求监听，配合HttpUtils使用
 * Created by xuxinghai on 2016/7/18.
 */
public abstract class HttpListener<T> {

    /**
     * vollery的成功回调
     */
    private Response.Listener<T> successListener = new Response.Listener<T>(){

        @Override
        public void onResponse(T response) {
//            String code = null;
//            try {
//                code = ((DataBean) response).getCode();
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//            if(TextUtils.equals("17",code)){//token有误,做下线操作;要不要清空本地呢?
////                AppApplication.getInstance().sendBroadcast(new Intent(NoticeReceiver.TOKENACTION));
//                AppApplication.getInstance().sendOrderedBroadcast(new Intent(NoticeReceiver.TOKENACTION),null);
//                UserInforManager.getInstance().setUserInfor(null);
//                UserDBDAO.getInstance().clearTable(UserSQLiteOpenHelper.USER_INFOR, AppApplication.getInstance());
//                UserDBDAO.getInstance().clearTable(UserSQLiteOpenHelper.USER_TASK, AppApplication.getInstance());
//
//            }
            onSuccess(response);
        }
    };

    /**
     * vollery的失败回调
     */
    private Response.ErrorListener errorListener = new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
           onError(error);
        }
    };

    public void onStart() {}

    public abstract void onError(VolleyError error);

    public abstract void onSuccess(T response);

    public Response.Listener<T> getSucesListener(){

        return successListener;
    }

    public Response.ErrorListener getErrorListener(){
        return errorListener;
    }

}
